import require from '@/utils/_require';

const API = {
  'GETROLE': '/admin/acl/role',
  'SAVE': '/admin/acl/role/save',
  'UPDATE': '/admin/acl/role/update',
  'REMOVE': '/admin/acl/role/remove',
  'GETMENUAll': '/admin/acl/permission',
  'GETMENUBYROLEID': '/admin/acl/permission/toAssign',
  'SAVEROLEMENU': '/admin/acl/permission/doAssign',
}

// 获取角色信息
export const reqGetRoleInfo = function (page, limit, roleName) {
  return require({
    url: API.GETROLE + `/${page}/${limit}`,
    method: 'get',
    params: { roleName }
  })
}

// 保存角色信息
export const reqSaveRoleInfo = function (data) {
  if (data.id) {
    return require({
      url: API.UPDATE,
      method: 'put',
      data
    })
  } else {
    return require({
      url: API.SAVE,
      method: 'post',
      data
    })
  }
}

// 删除对应id的角色
export const reqRemoverByID = function (roleId) {
  return require({
    url: API.REMOVE + `/${roleId}`,
    method: 'delete',
  })
}

// 获取全部权限
export const reqGetMenuAll = function () {
  return require({
    url: API.GETMENUAll,
    method: 'get',
  })
}

// 获取对应roleId的权限
export const reqGetMenuByRoleId = function (roleId) {
  return require({
    url: API.GETMENUBYROLEID + `/${roleId}`,
    method: 'get',
  })
}

// 保存对应roleId的权限
export const reqSaveRoleMenu = function (data) {
  return require({
    url: API.SAVEROLEMENU + `?roleId=${data.roleId}&permissionId=${data.permissionId}`,
    method: 'post',
  })
}